/*
    RAII 锁
*/
#ifndef LOCK_GUARD_HPP  
#define LOCK_GUARD_HPP  
  
#include <pthread.h>  
  
class LockGuard {  
private:  
    pthread_mutex_t* _mutex;  
  
public:  
    explicit LockGuard(pthread_mutex_t* mutex) : _mutex(mutex) {  
        if (_mutex != nullptr) {  
            pthread_mutex_lock(_mutex);  
        }  
    }  
  
    ~LockGuard() {  
        if (_mutex != nullptr) {  
            pthread_mutex_unlock(_mutex);  
        }  
    }  
  
    // 禁止拷贝和赋值  
    LockGuard(const LockGuard&) = delete;  
    LockGuard& operator=(const LockGuard&) = delete;  
};  
  
#endif // LOCK_GUARD_HPP